<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>详细页</title>
    <link rel="stylesheet" href="/bus/js/css/layui.css" media="all">
    <style>
        body {
            margin: 10px;
        }
    </style>
</head>
<body>

<forms class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">id</label>
        <div class="layui-input-block">
            <input type="text" name="id" id="id" lay-verify="" placeholder="127.0.0.1" autocomplete="off"
                   class="layui-input" th:value="${datasourceConfig.id} " disabled>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">数据库类型</label>
        <div class="layui-input-block">
            <select name="dbType" lay-search="" id="dbType" lay-filter="dbType" th:value="${datasourceConfig.dbType}">
             <option value="1"  th:selected="${datasourceConfig.dbType == 1} ? 'true' : 'false'" >Mysql</option>
            <option value="2"   th:selected="${datasourceConfig.dbType == 2} ? 'true' : 'false'" >Oracle</option>
            <option value="3"   th:selected="${datasourceConfig.dbType == 3} ? 'true' : 'false'" >Sql Server</option>
            <option value="4"   th:selected="${datasourceConfig.dbType == 4} ? 'true' : 'false'" >PostGreSql</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">host</label>
        <div class="layui-input-block">
            <input type="text" name="host" id="host" lay-verify="" placeholder="127.0.0.1" autocomplete="off"
                   class="layui-input" th:value="${datasourceConfig.host} " >
        </div>
    </div>

    <div class="layui-form-item">
            <label class="layui-form-label">port</label>
            <div class="layui-input-block">
                <input type="text" name="port" id="port" lay-verify="" placeholder="127.0.0.1" autocomplete="off"
                       class="layui-input" th:value="${datasourceConfig.port} ">
        </div>
    </div>

    <div class=" layui-form-item layui-form-text">
                <label class="layui-form-label">Database</label>
                <div class="layui-input-block">
                    <input type="text" name="dbName" id="dbName" placeholder="dpid" autocomplete="dbname"
                           class="layui-input"
                           th:value="${datasourceConfig.dbName}">
        </div>
    </div>

    <div class=" layui-form-item layui-form-text">
                    <label class="layui-form-label">username</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="username" placeholder="root" autocomplete="off"
                               class="layui-input"
                               th:value="${datasourceConfig.username}">
        </div>
    </div>

    <div class=" layui-form-item">
                        <label class="layui-form-label">password</label>
                        <div class="layui-input-block">
                            <input type="text" name="password" id="password" lay-verify="" placeholder="password"
                                   autocomplete="off"
                                   class="layui-input" th:value="${datasourceConfig.password} ">
        </div>
    </div>


    <div class=" layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-filter="csSubmitBtn" id="csSubmitBtn" hidden>测试连接</button>
                                <button class="layui-btn" lay-filter="saveSubmitBtn" id="saveSubmitBtn" hidden>保存
                                </button>
                            </div>
                        </div>

</forms>
<script src="/bus/js/layui.js"></script>
<script src="/bus/common.js"></script>
<script>
    var dropdown = layui.dropdown, util = layui.util
    //高级演示 - 各种组合

    $("#csSubmitBtn").click(function () {
        var datax = {
            dbName: $("#dbName").val()
            , dbType: $("#dbType").val()
            , delPrefix: ""
            , groupId: 1
            , host: $("#host").val()
            , isDeleted: 0
            , id: 0
            , packageName: ""
            , password: $("#password").val()
            , port: $("#port").val()
            , username: $("#username").val()
        };
        var urlx =  "/datasource/test"
        console.log(datax);
        commonUtil.sendRequest("POST", datax, urlx)
    })

    $("#saveSubmitBtn").click(function () {
        var datax = {
            dbName: $("#dbName").val()
            , dbType: $("#dbType").val()
            , delPrefix: ""
            , groupId: 1
            , isDeleted: 0
            , host: $("#host").val()
            , id:$("#id").val()
            , packageName: ""
            , password: $("#password").val()
            , port: $("#port").val()
            , username: $("#username").val()
        };
        var urlx =  "/datasource/update"
        console.log(datax);
        commonUtil.sendRequest("POST", datax, urlx)
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        // parent.layer.close(index); //再执行关闭
    })


</script>

</body>
</html>
